<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CommonRequest extends FormRequest
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 准备验证数据。
     *
     * @return void
     */
    protected function prepareForValidation(){}


    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [];
    }


    /**
     * Description:  messages
     * @author: JiaMeng <666@majiameng.com>
     * Updater:
     * @return array
     */
    public function messages()
    {
        return [];
    }

    /**
     * @Notes:过滤字段
     * @Interface filterData
     * @param $params
     * @return array
     * @author: Tinymeng <666@majiameng.com>
     * @Time: 2022/2/17 19:17
     */
    public function filterData($params = null): array
    {
        if($params == null){
            $params = $this->all();
        }
        $rules = $this->rules();

        //过滤草稿参数
        foreach ($params as $key=>$value){
            if(!isset($rules[$key])){
                unset($params[$key]);
            }
        }
        return $params;
    }

}
